function $(name) {
    return document.getElementsByName(name);
}
var designClass = "design_class", hideClass = "hide_class", browseClass = "browse_class", addClass = "add_class", editClass = "edit_class";

var upWindow = window.parent.frames["zwIframe"];
if (!upWindow) {
    upWindow = window.parent.frames["componentDiv"].frames["zwIframe"];
}
//关闭自定义扩张控件弹出窗口
function fy_dialog_close() {
    window.parent.$(".layui-layer-iframe").parent().find(".layui-layer-close").trigger("click");
}
function getUpFields(name) {
    return upWindow.$("[validate*='name:\"" + name + "\"']");
}
function getUpFieldsByFieldval(name) {
    return upWindow.$("[fieldval*='displayName:\"" + name + "\"']");
}
function getUpAccountFieldValue(name) {
    var field = getUpFields(name).eq(0);
    return {
        displayValue: field.is("span") ? field.text() : field.val(),
        value: eval("(" + field.parent("span").attr("fieldVal") + ")").value
    };
}

function getSpanFieldValue(name) {
    var field = getUpFieldsByFieldval(name).eq(0);
    return eval("(" + field.attr("fieldVal") + ")").value;
}
function setUpFieldValue(name, value) {
    upWindow.$("[fieldval*='displayName:\"" + name + "\"']").find("input").val(
            value);
    upWindow.$("[fieldval*='displayName:\"" + name + "\"']").find("input")
            .trigger("blur");
}

function _ajax(url, operator, isPost) {
    var xmlhttp = null;
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera,
        xmlhttp = new XMLHttpRequest();
    } else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4) {
            if (xmlhttp.status == 200) {
                text = xmlhttp.responseText;
                var data = eval("(" + text + ")");
                if (data.success)
                    operator(data);
                else
                    alert(data.data);
            } else {
                alert("连接服务器异常");
            }
            fy_dialog_close();
        }
    };
    xmlhttp.open(isPost ? "post" : "get", url + "&temp=" + Math.random(), true);
    xmlhttp.send();
}

function query() {
    var code = $("code")[0].value.replace(/ /g, "");
    if (code != "" && code.length == 6 && !isNaN(code)) {
        _ajax("../../../oa2hrController.do?method=queryMemberInfo_Leave&code="
                + code, function (data) {
                    for (var key in data) {
                        if (key != "success") {
                            if (key == '年休节余天数1') {
                                setUpFieldValue(key, (data[key].substr(0,1) == "." ? ("0"+data[key]) : data[key]));
                            } else {
                                setUpFieldValue(key, data[key]);
                            }
                        }
                    }
                });
    } else {
        alert("工号必须为6位数字");
    }
    return false;
}